package com.lb.shopguide.ui.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.lb.shopguide.R;
import com.lb.shopguide.config.UserConfigManager;
import com.lb.shopguide.constants.AppConstant;
import com.lb.shopguide.entity.BossActivityBean;
import com.lb.shopguide.entity.GuideActivityBean;
import com.lb.shopguide.ui.activity.ActivityActivityDetail;
import com.lb.shopguide.util.pic.ImageLoaderUtils;

/**
 * Created by kang on 2018/1/16.
 */

public class LbActivityItem extends LinearLayout {
    private ImageView ivBack;
    private ImageView ivActivityGoon;
    private ImageView ivActivityRec;
    private RelativeLayout layoutShadow;
    private BossActivityBean bean;
    private Context mContext;

    public static final int ACTIVITY_MINE = 0;
    public static final int ACTIVITY_HIS = 1;
    public static final int ACTIVITY_REC = 2;

    private int status;

    public LbActivityItem(Context context) {
        super(context);
        mContext = context;
        LayoutInflater.from(context).inflate(R.layout.item_boss_activity_item, this);
        ivBack = findViewById(R.id.iv_activity);
        ivActivityGoon = findViewById(R.id.iv_activity_goon);
        ivActivityRec = findViewById(R.id.iv_activity_rec);
        layoutShadow = findViewById(R.id.layout_shadow);
    }

    public void setBossActivityBean(BossActivityBean bean, int status) {
        this.bean = bean;
        if (status == ACTIVITY_MINE) {
            ivActivityGoon.setVisibility(VISIBLE);
        } else if (status == ACTIVITY_REC) {
            if (bean.getActivityStatus() != 0) {
                ivActivityRec.setVisibility(VISIBLE);
            } else {
                ivActivityRec.setVisibility(GONE);
            }
        } else if (status == ACTIVITY_HIS) {
            layoutShadow.setVisibility(VISIBLE);
        }
        ImageLoaderUtils.getGlideManager().asBitmap().load(bean.getPicUrl()).apply(ImageLoaderUtils.getSGCommonGlideOption(8)).into(ivBack);
    }

    public void enableClick() {
        ivBack.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, ActivityActivityDetail.class);
                Bundle bundle = new Bundle();
                bundle.putString(AppConstant.WEB_URL, bean.getInnerUrl() + "?token=" + UserConfigManager.getInstance(mContext).getUserToken() + "&type=android");
//                bundle.putString(AppConstant.WEB_TITLE, bean.getActivityName());//不传就不会有title
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
    }
}
